#! /bin/sh

changWiFi=$1
macAddress=$2

# Shell
# 如果有无线网卡，修改wifi mac adress ，如果没有修改有线网卡mac adress
if [ ${changWiFi} == 0 ]
then
    # Ethernet
    ethport=$(networksetup -listallhardwareports | grep 'Ethernet' -A 1 | grep 'en' | cut -d' ' -f2)
    target=$(openssl rand -hex 6 | sed 's/\(..\)/\1:/g; s/.$//')
    ifconfig $ethport ether $target
else
    # WiFi
    wifiport=$(networksetup -listallhardwareports | grep 'Wi-Fi' -A 1 | grep 'en' | cut -d' ' -f2)
    target=$(openssl rand -hex 6 | sed 's/\(..\)/\1:/g; s/.$//')
    ifconfig $wifiport ether $mac
    networksetup -setairportpower $wifiport off
    networksetup -setairportpower $wifiport on
fi
